<template>
	<view id="view">
		<u-cell title="出行日期"
				:value="utils.dateString(applyDate)"
				isLink clickable 
				@click="showPicker = true">
		</u-cell>
		<u-datetime-picker
				:show="showPicker"
				:value="new Date().getTime()"
				@close="showPicker = false"
				@cancel="showPicker = false" 
				@confirm="chooseDate"
				closeOnClickOverlay
				confirmColor="var(--theme-color)"
				mode="date"
		></u-datetime-picker>
		<u--textarea v-model="reason" placeholder="出行理由" ></u--textarea>
		<view style="width: 80vw;margin:10upx auto">
			<u-button @click="submit" type="primary" text="提交" color="var(--theme-color)"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPicker:false,
				applyDate:new Date(),
				reason:''
			}
		},
		onLoad() {

		},
		methods: {
			chooseDate(date){
				const that = this
				that.applyDate = new Date(date.value)
				that.showPicker = false
			},
			submit(){
				const that = this
				if(that.reason==""){
					uni.showToast({
						title:"请填写出行理由",
						icon:"error"
					})
					return
				}
				that.API({
					showLoading:true,
					url:"/user/apply",
					method:'put',
					data:{
						date_time:that.applyDate.getTime(),
						reason:that.reason,
					},
					code0:function(res){
						uni.showToast({
							title:"申请成功，请等待审批完成。",
						})
						uni.navigateBack()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	#view{

	}
</style>

